const resolve = require('@rollup/plugin-node-resolve');
const commonjs = require('@rollup/plugin-commonjs');
const typescript = require('@rollup/plugin-typescript');
const json = require('@rollup/plugin-json');
const peerDepsExternal = require('rollup-plugin-peer-deps-external');
const postcss = require('rollup-plugin-postcss');
const terser = require('@rollup/plugin-terser');

const packageJson = require('./package.json');

module.exports = [
  {
    input: 'index.ts',
    output: [
      {
        file: packageJson.main,
        format: 'cjs',
        sourcemap: true,
        name: 'AnyFrontUI',
      },
      {
        file: packageJson.module,
        format: 'esm',
        sourcemap: true,
      },
    ],
    plugins: [
      peerDepsExternal(),
      resolve({
        browser: true,
        preferBuiltins: false,
      }),
      commonjs(),
      json(),
      typescript({
        tsconfig: './tsconfig.lib.json',
        declaration: true,
        declarationDir: './dist',
        exclude: [
          '**/*.test.*', 
          '**/*.spec.*',
          'src/layouts/**/*',
          'src/pages/**/*',
          'src/models/**/*',
          'src/hooks/**/*',
          'src/access.ts',
          'src/app.ts'
        ],
      }),
      postcss({
        extract: true,
        minimize: true,
        use: {
          sass: null,
          stylus: null,
          less: { javascriptEnabled: true },
        },
      }),
      terser.default(),
    ],
    external: [
      'react',
      'react-dom',
      'antd',
      '@ant-design/icons',
      '@ant-design/pro-components',
      'dayjs',
      'js-cookie',
      'json-bigint',
      'lodash',
      'react-intl',
      'umi-request',
    ],
  },
];
